#include "CDKey.h"

#define CONFIG_ITEM(TYPE,ID) \
    ID = new TYPE; \
    ID->setObjectName(#ID); \
    ID->translatedName = tr(#ID);


void CDKey::verify()
{
    if (m_cdKey->get() == "123")
    {
        m_keyLevel = TS::CDKeyLevel::LifeLong;
        writeToFile();
    }
    else
        m_keyLevel = TS::CDKeyLevel::NotValid;

    emit keyLevelChanged(m_keyLevel);
}

TS::CDKeyLevel CDKey::keyLevel()
{
    return m_keyLevel;
}

CDKey::CDKey(QObject *parent) : ConfigDataModel (parent)
{
    CONFIG_ITEM(ItemString, m_cdKey)
    //
    ensureItemRegisterd();
    //
    m_keyLevel = TS::CDKeyLevel::LifeLong;
}


void CDKey::resetSelf()
{
    m_cdKey->set("");
    verify();
    writeToFile();
}


#undef CONFIG_ITEM

